package org.uni_hi.muus.server.util;

import org.uni_hi.muus.util.StringUtil;

public class HTTPServerCodes {
	
//	private static Hashtable _statusTable=null;
	
	public final static String HTTP_SERVER_NAME="Mobile uueb Server";

	public final static String HTTP_GET="GET";
	public final static String HTTP_POST="POST";
	public final static String HTTP_VERSION="HTTP/1.0";
//	public final static String HTTP_CONTENT_TYPE="Content-Type: ";
//	public final static String HTTP_CONTENT_LENGTH="Content-Length: ";
		
	public final static int 
		HTTP_CODE_200=200,
		HTTP_CODE_400=400,
		HTTP_CODE_401=401,
		HTTP_CODE_403=403,
		HTTP_CODE_404=404,
		HTTP_CODE_405=405,
		HTTP_CODE_500=500,
		HTTP_CODE_501=501,
		HTTP_CODE_504=504,
		HTTP_CODE_505=505;
	
	public final static String 
		HTTP_STATUS_200="200 OK",
		HTTP_STATUS_400="400 Bad Request",
		HTTP_STATUS_401="401 Unauthorized",
		HTTP_STATUS_403="403 Forbidden",
		HTTP_STATUS_404="404 Not Found",
		HTTP_STATUS_405="404 Method Not Allowed",
		HTTP_STATUS_500="500 Internal Server Error",
		HTTP_STATUS_501="501 Not Implemented",
		HTTP_STATUS_504="504 Gateway time-out",
		HTTP_STATUS_505="505 HTTP version not supported";
	
	private final static Object[][] HTTP_STATUS_CODES=new Object[][]{
		{new Integer(HTTP_CODE_200),HTTP_STATUS_200},
		{new Integer(HTTP_CODE_400),HTTP_STATUS_400},
		{new Integer(HTTP_CODE_401),HTTP_STATUS_401},
		{new Integer(HTTP_CODE_403),HTTP_STATUS_403},
		{new Integer(HTTP_CODE_404),HTTP_STATUS_404},
		{new Integer(HTTP_CODE_405),HTTP_STATUS_405},
		{new Integer(HTTP_CODE_500),HTTP_STATUS_500},
		{new Integer(HTTP_CODE_501),HTTP_STATUS_501},
		{new Integer(HTTP_CODE_504),HTTP_STATUS_504},
		{new Integer(HTTP_CODE_505),HTTP_STATUS_505}}; 

	
	public final static String 
		MuuS_CONFIG_PARAMETER="config",
		MuuS_ABOUT_PARAMETER="about",
		MuuS_START_PARAMETER="start";
	
	public final static String 
		MuuS_CONFIG_FILE="/web/config.muus",
		MuuS_ABOUT_FILE="/web/about.muus",
		MuuS_ABOUT_EDIT_FILE="/web/about_edit.muus",
		MuuS_START_FILE="/web/start.muus";
	
	public final static String MuuS_EDIT_VALUE="edit";
	
	public final static String 
		HTTP_PAGE_400=getDoc4Stat(HTTP_STATUS_400),
		HTTP_PAGE_404=getDoc4Stat(HTTP_STATUS_404),
		HTTP_PAGE_501=getDoc4Stat(HTTP_STATUS_501);
	
	public static String getDoc4Stat(String stat){
		return StringUtil.getHTMLDocforStatus(stat,"");
	}
	
	public static String getDoc4Stat(String stat,String expl){
		return StringUtil.getHTMLDocforStatus(stat,expl);
	}
	
	public static String getString4Code(int code){
		Integer c=new Integer(code);
		for(int i=0;i<HTTP_STATUS_CODES.length;i++){
			if(HTTP_STATUS_CODES[i][0].equals(c)){
				return HTTP_STATUS_CODES[i][1].toString();
			}
		}
		System.out.println(code);
		return null;
	}

	/*
	private static Hashtable getStatusTable(){
		if(_statusTable==null){
			_statusTable=initStatusTable();
		}
		return _statusTable;
	}
	
	private static Hashtable initStatusTable(){
		Hashtable statusTable=new Hashtable(); 
		for(int i=0;i<HTTP_STATUS_CODES.length;i++){
			statusTable.put(HTTP_STATUS_CODES[i][0],HTTP_STATUS_CODES[i][1]);
		}
		return statusTable;
	}
	*/
}
